package squareBorderPackage;

import static org.junit.Assert.*;

import java.math.BigDecimal;
import java.util.*;

import org.junit.*;

import temperaturePackage.*;

/**
 * A class collecting tests for the class of rocks.
 * 
 * @version 1.0
 * @author Esther Alberts & Jessa Bekker
 */
public class RockSquareTest {
	
	/**
	 * Instance variable referencing squares that may change during individual
	 * tests.
	 */
	private static RockSquare defaultRock, terminatedRock;
	
	/**
	 * Instance variable referencing maps that may change during individual
	 * tests.
	 */
	private static HashMap<Direction, Border> allWalls, notAllWalls, wrongDirection;
	
	/**
	 * Set up a mutable test fixture.
	 * 
	 * @post 	The variable defaultRock references a new rockSquare with in its southDirection a normalSquare
	 * 			with 60 degree celsius and 10 percent humidity and in its westDirection a normalSquare with 60 degree celsius and 10 percent humidity.
	 * @post 	The variable defaultRock references a new terminated rockSquare
	 * @post 	The variable allWalls references a new map with six walls.
	 * @post 	The variable notAllWalls references a new map with six walls except for the openborder in the northDirection.
	 * @post 	The variable wrongDirection references a new map with six walls except for the openborder in the northDirection, 
	 * 			added in a illegal way.
	 */
	@BeforeClass
	public static void setUp(){
		defaultRock = new RockSquare();
		defaultRock.getBorderAt(Direction.SOUTH).attachTo(new NormalSquare(new Temperature(20, TemperatureUnit.CELSIUS), BigDecimal.TEN), Direction.NORTH);
		defaultRock.getBorderAt(Direction.WEST).attachTo(new NormalSquare(new Temperature(60, TemperatureUnit.CELSIUS), BigDecimal.TEN), Direction.EAST);
		
		
		terminatedRock = new RockSquare();
		terminatedRock.terminate();
		
		allWalls = new HashMap<Direction, Border>();
		notAllWalls = new HashMap<Direction, Border>();
		wrongDirection = new HashMap<Direction, Border>();
		for (Direction direction : Direction.getListOfDirections()){
			allWalls.put(direction, new Wall(false, new NormalSquare(), direction.getOpposite()));
			notAllWalls.put(direction, new Wall(false, new NormalSquare(), direction.getOpposite()));
			wrongDirection.put(direction, new Wall(false, new NormalSquare(), direction.getOpposite()));
		}
		notAllWalls.put(Direction.NORTH, new OpenBorder(new NormalSquare(), Direction.SOUTH));
		wrongDirection.put(Direction.NORTH, new OpenBorder(new NormalSquare(), Direction.WEST));
	}
	
	@Test
	public void hasOnlyWalls_True() {
		assertTrue(defaultRock.hasOnlyWalls(allWalls));
	}
	
	@Test
	public void hasOnlyWalls_False() {
		assertFalse(defaultRock.hasOnlyWalls(notAllWalls));
	}
	
	@Test
	public void areAppropriateBorders_True() {
		assertTrue(defaultRock.areAppropriateBorders(allWalls));
	}
	
	@Test
	public void areAppropriateBorders_NotAllWalls() {
		assertFalse(defaultRock.areAppropriateBorders(notAllWalls));
	}
	
	@Test
	public void areAppropriateBorders_superAppropriateFalse() {
		assertFalse(defaultRock.areAppropriateBorders(wrongDirection));
	}
	
	@Test
	public void getObstacleAt_True() {
		assertTrue(defaultRock.getObstacleAt(Direction.NORTH));
		assertTrue(defaultRock.getObstacleAt(Direction.SOUTH));
		assertTrue(defaultRock.getObstacleAt(Direction.WEST));
		assertTrue(defaultRock.getObstacleAt(Direction.EAST));
		assertTrue(defaultRock.getObstacleAt(Direction.FLOOR));
		assertTrue(defaultRock.getObstacleAt(Direction.CEILING));
	}
	
	@Test
	public void getNbOfSquaresInSpace_One() {
		assertTrue(defaultRock.getNbOfSquaresInSpace() == 1);
	}
	
	@Test
	public void getSpace_Terminated() {
		assertEquals(terminatedRock.getSpace(), null);
	}
	
	@Test
	public void getSpace_NotTerminated() {
		assertTrue(defaultRock.getSpace().size() == 1);
		assertTrue(defaultRock.getSpace().contains(defaultRock));
	}
	
	@Test
	public void getTemperature_LegalCase(){
		assertTrue(defaultRock.getTemperature().getNumeral() == 40);
		assertTrue(defaultRock.getTemperature().getUnit() == TemperatureUnit.CELSIUS);
	}
	
	@Test
	public void getHumidity_LegalCase() {
		assertTrue(defaultRock.getHumidity() == BigDecimal.ZERO);
	}
	
	@Test
	public void getRustDamage_LegalCase() {
		assertEquals(defaultRock.getRustDamage(), 0);
	}
}
